/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 2006 Hangzhou C-SKY Microsystems co.,ltd.
 * Copyright (C) 2006  Li Chunqiang (chunqiang_li@c-sky.com)
 * Copyright (C) 2009  Ye Yun (yun_ye@c-sky.com)
 */

#include <linux/types.h>
#include <linux/dma-mapping.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/scatterlist.h>
#include <linux/string.h>

#include <asm/cache.h>

void *dma_alloc_coherent(struct device *dev, size_t size,
        dma_addr_t * dma_handle, gfp_t gfp)
{
	unsigned int *ret;

	gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
	if(dev == NULL || dev->coherent_dma_mask < DMA_BIT_MASK(24))
	{
		gfp |= __GFP_DMA;
	}
	ret = (void *) __get_free_pages(gfp, get_order(size));
	if(ret)
	{
		memset(ret, 0, size);
		*dma_handle = virt_to_phys(ret);
		ret = UNCACHE_ADDR(ret);
	}
	return (void *)ret;
}
EXPORT_SYMBOL(dma_alloc_coherent);

void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
        dma_addr_t dma_handle)
{
	free_pages((unsigned long) vaddr, get_order(size));
}
EXPORT_SYMBOL(dma_free_coherent);

void dma_free_noncoherent(struct device *dev, size_t size,
                         void *vaddr, dma_addr_t dma_handle)
{
}
EXPORT_SYMBOL(dma_free_noncoherent);

void *dma_alloc_noncoherent(struct device *dev, size_t size,
                           dma_addr_t *dma_handle, gfp_t flag)
{
	return NULL;
}
EXPORT_SYMBOL(dma_alloc_noncoherent);

dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
    enum dma_data_direction direction)
{
	return 0;
}

EXPORT_SYMBOL(dma_map_single);

void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
    enum dma_data_direction direction)
{
}

EXPORT_SYMBOL(dma_unmap_single);

dma_addr_t dma_map_page(struct device *dev, struct page *page,
    unsigned long offset, size_t size, enum dma_data_direction direction)
{
	return 0;
}

EXPORT_SYMBOL(dma_map_page);

int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
{
	return 0;
}

EXPORT_SYMBOL(dma_mapping_error);

